fix(qlinear): size GPTQ buffers by bits/pack_dtype_bits#2985
Merged
Conversation
…ck_factor or 32 The number of packed words is ceil(dim * bits / pack_dtype_bits), not ceil(dim / pack_factor). - In _register_gptq_buffers, use in_features*bits/pack_dtype_bits and out_features*bits/pack_dtype_bits for qweight/qzeros rows/cols. - In pack_original, use dim*bits/pack_dtype_bits for both qweight and qzeros. This is equivalent to the previous pack_factor formula for 2/4/8-bit, and correct for 3-bit and non-32-bit pack dtypes (int8/int16).
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_register_gptq_buffersandPackableQuantLinear.pack_originalsized packedqweight/qzeroswithceil(dim / pack_factor)(wherepack_factor = pack_dtype_bits // bits) or, after the previous 3-bit fix, a hardcoded32. Both are wrong whenpack_dtype_bitsdoes not equal32or whenpack_dtype_bits / bitsis not an integer (3-bit).The correct number of packed words is
ceil(dim * bits / pack_dtype_bits).Changes
GPTQQuantLinear._register_gptq_buffers:qweightrows andqzeroscolumns now usemath.ceil(dim * self.bits / self.pack_dtype_bits).PackableQuantLinear.pack_original:qweightandqzerosallocation now usesmath.ceil(dim * self.bits / self.pack_dtype_bits)instead of32.For 2/4/8-bit these formulas are equivalent to the old
ceil(dim / pack_factor). For 3-bit (pack_dtype_bits == 32) this givesceil(dim * 3 / 32), matching the 32-value packing loop and thepack_block/pack_gpupaths. Forint8/int16pack dtypes this no longer under-allocates the buffer.Verification
ruff check gptqmodel/nn_modules/qlinear/__init__.py: passedgit diff --check: passedpytest tests/test_pack.py tests/kernels/test_qlinear_hierarchy.py -q: 27 passed